package com.wbu.estatemanagement.service.impl;

import com.wbu.estatemanagement.dao.ParkingMapper;
import com.wbu.estatemanagement.domain.Parking;
import com.wbu.estatemanagement.service.ParkingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class ParkingServiceImpl implements ParkingService {

    @Autowired
    ParkingMapper parkingMapper;

    @Override
    public Map<String,Integer> coutParking() {
        List<Parking> parkings = parkingMapper.selectAll();
        int A = parkings.stream().filter(s -> s.getLocal().equals("A")).collect(Collectors.toList()).size();
        int B = parkings.stream().filter(s -> s.getLocal().equals("B")).collect(Collectors.toList()).size();
        int C = parkings.stream().filter(s -> s.getLocal().equals("C")).collect(Collectors.toList()).size();
        int D = parkings.stream().filter(s -> s.getLocal().equals("D")).collect(Collectors.toList()).size();
        int E = parkings.stream().filter(s -> s.getLocal().equals("E")).collect(Collectors.toList()).size();
        Map<String,Integer> count= new HashMap<>();
        count.put("A",A);
        count.put("B",B);
        count.put("C",C);
        count.put("D",D);
        count.put("E",E);
        return count;

    }
}
